/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package au.edu.swin.swinvehicle.vehiclelicencetype;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Administrator
 */
@Stateless
public class VehicleLicenceTypeManagerBean implements VehicleLicenceTypeManagerRemote {

    @PersistenceContext
    private EntityManager em;

    /**
     * Get all vehicle licence types
     * 
     * @return
     * @throws au.edu.swin.swinvehicle.vehiclelicencetype.VehicleLicenceTypeManagerException
     */
    public List<VehicleLicenceTypeTO> getAllVehicleLicenceTypes() throws VehicleLicenceTypeManagerException {
        try {
            List<VehicleLicenceTypeTO> results = new ArrayList<VehicleLicenceTypeTO>();
            Query allVehicleLicenceTypesQuery = this.em.createNamedQuery("findAllVehicleLicenceTypes");
            List dbResults = allVehicleLicenceTypesQuery.getResultList();
            for (int i = 0; i < dbResults.size(); i++) {
                VehicleLicenceTypeEntity vlt = (VehicleLicenceTypeEntity) dbResults.get(i);
                results.add(vlt.getData());
            }
            return results;
        } catch (Exception e) {
            throw new VehicleLicenceTypeManagerException("Cannot get all vehicle licence types", e);
        }
    }
}
